package com.ruoyi.web.controller.iot;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.vo.IotPassthroughParams;
import com.ruoyi.system.domain.vo.IotPassthroughVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IotPassthrough;
import com.ruoyi.system.service.IIotPassthroughService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 公司名称：未可自动化 <br/>
 * 作者：weikeauto <br/>
 */
@RestController
@RequestMapping("/iot/passthrough")
public class IotPassthroughController extends BaseController
{
    @Autowired
    private IIotPassthroughService iotPassthroughService;

    /**
     * 查询【请填写功能名称】列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IotPassthrough iotPassthrough)
    {
        startPage();
//        List<IotPassthroughVo> list = iotPassthroughService.selectIotPassthroughList(iotPassthrough);
        List<IotPassthroughVo> list = iotPassthroughService.selectNewIotPassthroughList(iotPassthrough);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IotPassthrough iotPassthrough)
    {
        List<IotPassthrough> list = iotPassthroughService.selectIotPassthroughList(iotPassthrough);
        ExcelUtil<IotPassthrough> util = new ExcelUtil<IotPassthrough>(IotPassthrough.class);
        util.exportExcel(response, list, "【请填写功能名称】数据");
    }

    /**
     * 获取【请填写功能名称】详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(iotPassthroughService.selectIotPassthroughById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IotPassthroughParams iotPassthroughParams)
    {
        return toAjax(iotPassthroughService.insertIotPassthrough(iotPassthroughParams));
    }

    /**
     * 修改【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IotPassthroughParams iotPassthroughParams)
    {
        return toAjax(iotPassthroughService.updateNewIotPassthrough(iotPassthroughParams));
    }

    /**
     * 删除【请填写功能名称】
     */
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(iotPassthroughService.deleteIotPassthroughByIds(ids));
    }

    /**
     * 状态修改
     */
    @Log(title = "策略管理", businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeStatus(@RequestBody IotPassthrough iotPassthrough)
    {
        iotPassthrough.setUpdateBy(getUsername());
        iotPassthrough.setUpdateTime(DateUtils.getNowDate());
        return toAjax(iotPassthroughService.changeStatus(iotPassthrough));
    }

    @GetMapping("/passthroughDetail")
    public AjaxResult passthroughDetail(@RequestParam("passthroughId")Long passthroughId)
    {
        IotPassthroughVo iotPassthroughVo = iotPassthroughService.selectIotPassthroughDetailById(passthroughId);
        return success(iotPassthroughVo);
    }

}
